package com.bum.game.bo;

import com.bum.game.util.Util;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Text;

public class Game {
	public static void save(String code, String title, int size, String jar, String jad, String img, String intro, String content) {
		Entity game = get(code);
		if (game == null) {
			game = new Entity("Game", code);
			game.setProperty("code", code);
			game.setProperty("title", title);
			game.setProperty("size", size);
			game.setProperty("jar", jar);
			game.setProperty("jad", jad);
			game.setProperty("img", img);
			game.setProperty("intro", new Text(intro));
			game.setProperty("content", new Text(content));
		} else {
			game.setProperty("code", code);
			game.setProperty("title", title);
			game.setProperty("size", size);
			game.setProperty("jar", jar);
			game.setProperty("jad", jad);
			game.setProperty("img", img);
			game.setProperty("intro", new Text(intro));
			game.setProperty("content", new Text(content));
		}
		Util.persistEntity(game);
	}

	public static Entity get(String code) {
		Key key = KeyFactory.createKey("Game", code);
		return Util.findEntity(key);
	}

	public static Iterable<Entity> getAll() {
		Iterable<Entity> entities = Util.listEntities("Game", null, null);
		return entities;
	}
}
